﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using System.Collections.Generic;
using LinQDemo.Models;
using System.Data.Linq;

namespace LinQDemo.Models
{
    public partial class Student
    {
        partial void onValidate(ChangeAction action);
        public bool IsValid
        {
            get { return (GetRuleViolations().Count() == 0); }
        }

        public IEnumerable<RuleViolation> GetRuleViolations()
        {
            if (String.IsNullOrEmpty(StudentID.Trim()))
                yield return new RuleViolation("StudentID required", "StudentID");

            if (String.IsNullOrEmpty(StudentName.Trim()))
                yield return new RuleViolation("StudentName required", "StudentName");

            if (String.IsNullOrEmpty(ClassID.Trim()))
                yield return new RuleViolation("ClassID required", "ClassID");

            yield break;
        }

        partial void onValidate(ChangeAction action)
        {
            if (!IsValid)
                throw new ApplicationException("Rule violations prevent saving");
        }
    }
}
